<template>
  <div class="op">
    <div class="iptRow">
      <div class="block">
        <el-date-picker
          v-model="value"
          type="daterange"
          align="right"
          unlink-panels
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </div>
      <el-col style="width:10px"></el-col>
      <el-button icon="el-icon-search" circle @click="getOpList"></el-button>
    </div>
    <div class="record">
      <el-table :data="tableList" style="width: 100%">
        <el-table-column width="40px"></el-table-column>
        <el-table-column prop label="序号" width="80">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 + (pageIndex - 1) * pageSize }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="opTable" label="操作记录" width="200"></el-table-column>
        <el-table-column prop="opAdminName" label="操作人" width="150"></el-table-column>

        <el-table-column prop="opTime" label="操作时间" width="200"></el-table-column>
        <el-table-column prop="opData" label="数据"></el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        align="right"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageIndex"
        :page-sizes="[5, 10]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="totalNumber"
        style="margin-top: 58px; margin-bottom: 40px"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      pageIndex: 1,
      pageSize: 10,
      totalNumber: 0,
      tableList: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      value: ""
    };
  },
  created() {
    this.getOpList();
  },
  methods: {
    getOpList() {
      console.log(this.value);
      let startTime = "";
      let endTime = "";
      if (this.value == null) {
        startTime = "";
        endTime = "";
      } else {
        startTime = this.value[0];
        endTime = this.value[1];
      }
      let params = {
        startTime: startTime,
        endTime: endTime,
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      };
      this.$axios
        .get("/api/CjwOperationList/GetOpList", { params })
        .then(res => {
          this.tableList = res.data.operationLists;
          this.totalNumber = res.data.total;
          console.log(this.tableList);
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getOpList();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getOpList();
    }
  }
};
</script>

<style scoped>
.iptRow {
  margin: 10px;
  display: flex;
}
</style>